<!--
@Description: 苹果游客登录
@Author: fcg
-->
<template>
	<view>
		<button @tap="touristLogin" v-if="isIos && !isOnStore" class="tourist">游客登录</button>
	</view>
</template>

<script>
	import {
		isOnStore,
		visitorLogin,
	} from '@/config/api.js'
	export default {
		data() {
			return {
				isIos: false
			};
		},
		methods: {
			async touristLogin() {

				const res = await isOnStore();
				const isOnAppStore = res.data.isOnStore;
				this.$u.vuex('isOnStore', isOnAppStore);
				if (!isOnAppStore) {
					uni.setTabBarItem({
						index: 2,
						visible: false,
					})

				} else {
					uni.setTabBarItem({
						index: 2,
						visible: true,
					})

				}
				const {
					deviceId
				} = uni.getSystemInfoSync();
				console.log('res:', deviceId)
				visitorLogin({
					app_id: deviceId
				}).then(res => {
					if (res.code != 1) {
						uni.showToast({
							icon: "none",
							title: res.msg,
						})
					}
					this.$u.vuex('vuex_token', res.data.userinfo.token);
					if (res.data.userinfo.type == 1) {
						if (res.data.userinfo.school_id != 0) {
							uni.switchTab({
								url: '/pages/index/index'
							})
						} else {
							uni.navigateTo({
								url: '/pages/login/set_user_info'
							})
						}
					} else if (res.data.userinfo.type == 2) {
						if (res.data.userinfo.company != '') {
							uni.switchTab({
								url: '/pages/index/index'
							})
						} else {
							uni.navigateTo({
								url: '/pages/login/set_user_info'
							})
						}
					}
				})

			}
		},
		created() {
			if (uni.getSystemInfoSync().platform == "ios") {
				this.isIos = true
			}
		}
	}
</script>

<style lang="scss">
	.tourist {
		background-color: rgba(231, 23, 59, 1);
		color: #FFFFFF;
		font-size: 28rpx;
		padding: 8rpx 0;
		border-radius: 46rpx;
		width: 80%;
	}
</style>
